<template>
	<view class="box">
		<view class="top">
			<view class="top_hezi">
				<view class="left">
					<image src="../../static/x.png" mode=""></image>
					<span>欢迎来到项目中心</span>
				</view>
				<view class="right">
					<image src="../../static/eb5fdc1be6f08e2209ddb4be3537113b310e77c11b4fe4-DA5M8Y@2x.png" mode="">
					</image>
				</view>
			</view>
		</view>
		<view class="neir">
			<view class="neir_top">
				<span>请登录账号</span>
			</view>
			<view class="name">
				<span>账号</span>
				<input type="text" v-model="params.username" placeholder="请输入您的账号" placeholder-class="mohu" />
			</view>
			<view class="name">
				<span>密码</span>
				<input type="text" v-model="params.password" placeholder="请输入您的密码" placeholder-class="mohu" />
			</view>
			<view class="name">
				<span>验证码</span>
				<view class="yz">
					<input  type="number" v-model="params.code" placeholder="请输入验证码" placeholder-class="mohu" />
					<img :src="params.codeurl" alt="" srcset="" @click="getcode()"/>
				</view>
			</view>
			<button @click="login">登录</button>
		</view>
	</view>
</template>

<script>
	import {
		getlogin,
		getText,
		getUserinfo
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				params:{
					codeurl: '',
					username: '',
					password: '',
					code:'',
					uuid:''
				}
			}
		},
		onLoad() {
			this.getcode()
		},
		methods: {
			getcode(){
				getText().then(res => {
					this.params.codeurl = "data:image/gif;base64," + res.img;
					this.params.uuid =  res.uuid
				})
			},
			login() {
				if(this.params.username == ''){
					uni.showToast({
						title: '请输入账号',
						duration:2000,
						mask:false,
						icon:"none"
					})
				}else if( this.params.password == ''){
					uni.showToast({
						title:'请输入密码',
						duration:2000,
						mask:false,
						icon:"none"
					})
					
				}else if(this.params.code == ''){
					uni.showToast({
						title:'请输入验证码',
						duration:2000,
						mask:false,
						icon:"none"
					})
				}else{
					getlogin(this.params).then(res=>{
						if(res.code == 200){
							uni.setStorageSync('token',res.token)
							getUserinfo().then(res=>{
								uni.setStorageSync('user', res.user)
								console.log(res.roles[0]);
								if(res.roles[0] == 'hezuofang'){
									uni.redirectTo({
										url: '/pages/indexs/home_Partner'
									})
									uni.setStorageSync('name', res.roles[0])
								}else if(res.roles[0] == 'sheji' || res.roles[0] == 'cehui'){
									uni.redirectTo({
										url: '/pages/index/home_test'
									})
									uni.setStorageSync('name', res.roles[0])
								}else{
									uni.showToast({
										title: '账号密码错误',
										duration: 2000,
										mask: false,
										icon: "none"
									})
								}
							})
						}else{
							this.getcode()
						}
					})
				}
		
			}
		},
	
	}
</script>

<style lang="scss" scoped>
	.top {
		width: 100%;
		height: 650rpx;
		// background-image: url('../../static/bj@2x.png');
		display: flex;
		align-items: center;
	}

	.neir {
		width: 100%;
		height: 1048rpx;
		background: #FFFFFF;
		box-shadow: -2rpx -43rpx 144rpx 0rpx rgba(122, 203, 202, 0.19);
		border-radius: 50rpx 50rpx 0rpx 0rpx;
		margin-top: -10%;

		button {
			width: 622rpx;
			height: 80rpx;
			background: #065CF7;
			border-radius: 40rpx;
			font-family: Alibaba PuHuiTi 2.0;
			font-weight: normal;
			font-size: 34rpx;
			color: #FFFFFF;
			margin-top: 125rpx;
		}

		.neir_top {
			padding: 40rpx;

			span {
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 38rpx;
				color: #2B2B2B;
				line-height: 48rpx;
			}
		}

		.name {
			margin: 20rpx;
			margin-left: 40rpx;
			border-bottom: 1px #DCDCDC solid;
			span {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #2B2B2B;
				line-height: 48rpx;
			}

			input {
				height: 100rpx;
			}

			.mohu {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #C7C7C7;
				line-height: 48rpx;
			}
		}
	}

	.top_hezi {
		display: flex;
		justify-content: space-around;
		width: 100%;

		.left {
			display: flex;
			flex-direction: column;

			span {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #065CF7;
				line-height: 48rpx;
			}

			image {
				width: 266rpx;
				height: 58rpx;
			}
		}

		.right {
			image {
				width: 206rpx;
				height: 195rpx;
			}
		}
	}
	.yz{
		display: flex;
		justify-content: space-between;
		img{
			width: 160rpx;
			height: 100rpx;
		}
	}
</style>